sql_statement = ""

with open('clientes.tsv') as f:
    i = 0
    for line in f:
        client = line.rstrip('\n').split('\t')
        barrio = ""
        if client[1] == '""':
            barrio = 'ZARAGOCILLA'
        else:
            barrio = client[1]
        sql_statement += 'INSERT INTO "MaeCliente" ("usuarioGrab", "usuarioUltMod", "activo", "codMaeCliente", "codMaeBarrio", "nombreMaeCliente", "telefono", "direccion", "eMail", "tagFiltro")\n'
        sql_statement += "VALUES ('ADMIN', 'ADMIN', TRUE, '" + client[0] + "', '" + barrio + "', '" + client[2] + "', '" + client[3] + "', '" + client[4] + "', '" + client[5] + "', coalesce('" + client[0] + "','') || '	- ' || coalesce('" + client[2] + "',''));\n\n"

with open('insertar_maestros_clientes.sql', 'w') as f:
    f.write(sql_statement)

